package com.acme.service;

import java.io.IOException;
import java.util.logging.Logger;

import com.acme.domain.Order;
import com.acme.domain.response.OrderChangeInfo;
import com.acme.domain.response.SubscribeResponse;
import com.acme.domain.usermap.UsersResponse;

public class SendService {
	
	private static Logger sendLogger = Logger.getLogger(SendService.class.getName());
	public static void send(Object msg) throws IOException{
		if (msg instanceof OrderChangeInfo){
			Order order = ((OrderChangeInfo)msg).getOrder();
			sendLogger.info("Order with id " + order.getId() +
					" was " + order.getStatus() + " in stock " + order.getStockName());
			UsersResponse.addResponse( ((OrderChangeInfo)msg).getOrder().getClientName(),msg);
		} else if ( msg instanceof SubscribeResponse) {
			UsersResponse.addResponse(((SubscribeResponse)msg).getUsername() ,msg);
		}
	}
}
